package com.dht.xiao.jianye.command.base.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author :      fangbingran
 * @aescription : todo(这里用一句话描述这个类的作用)
 * @date :        2019/08/09  20:25
 */
public class BigDecimalUtil {
    public static BigDecimal add(double one, double two) {
        BigDecimal num1 = new BigDecimal(one);
        BigDecimal num2 = new BigDecimal(two);
        return num1.add(num2);
    }

    public static BigDecimal subtract(double one, double two) {
        BigDecimal num1 = new BigDecimal(one);
        BigDecimal num2 = new BigDecimal(two);
        return num1.subtract(num2);
    }

    public static BigDecimal multiply(double one, double two) {
        BigDecimal num1 = new BigDecimal(one);
        BigDecimal num2 = new BigDecimal(two);
        return num1.multiply(num2);
    }

    public static BigDecimal divide(double one, double two) {
        return divide(one, two, 4, RoundingMode.HALF_UP);
    }

    public static BigDecimal divide(double one, double two, int scale) {
        BigDecimal num1 = new BigDecimal(one);
        BigDecimal num2 = new BigDecimal(two);
        return num1.divide(num2, scale, RoundingMode.HALF_UP);
    }

    public static BigDecimal divide(double one, double two, int scale, RoundingMode roundingMode) {
        BigDecimal num1 = new BigDecimal(one);
        BigDecimal num2 = new BigDecimal(two);
        return num1.divide(num2, scale, roundingMode);
    }
}
